package com.example.easyExcelListener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.example.entity.Region;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author ZHAO Yudong
 * @Date 2020/10/27 16:41
 * @description：
 */
@Slf4j
public class RegionListener extends AnalysisEventListener<Region> {

    private String province = null;

    @Override
    public void invoke(Region region, AnalysisContext analysisContext) {

        if (StringUtils.isNotBlank(region.getProvince())) {
            province = region.getProvince();
        }
        if (region.getProvince() == null) {
            region.setProvince(province);
        }
        log.info("region = {}", JSON.toJSON(region));
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
